package com.port.schedule;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;


@Component
@Slf4j
@RequiredArgsConstructor
public class ScheduleJobManager {


    /**
     * 装配所有定时任务
     */
    private final List<ScheduleService> scheduleServiceList;


    /**
     * 每秒
     */
    @Scheduled(cron = "*/1 * * * * ?")
    public void everySecond() {
        scheduleServiceList.forEach(ScheduleService::everySecond);
    }

    /**
     * 每分钟
     */
    @Scheduled(fixedDelay = 60000, initialDelay = 1000)
    public void everyMinute() {
        scheduleServiceList.forEach(ScheduleService::everyMinute);
    }

    /**
     * 每五分钟
     */
    @Scheduled(cron = "0 */5 * * * ?")
    public void everyFiveMinute() {
        scheduleServiceList.forEach(ScheduleService::everyFiveMinute);
    }

    /**
     * 每小时
     */
    @Scheduled(fixedDelay = 3600000, initialDelay = 1000)
    public void everyHour() {
        scheduleServiceList.forEach(ScheduleService::everyHour);
    }
    /**
     * 每10分钟
     */

    @Scheduled(fixedDelay = 600000, initialDelay = 1000)
    public void everyTenMinute() {
        scheduleServiceList.forEach(ScheduleService::everyTenMinute);
    }

    /**
     * 半小时
     */
    @Scheduled(fixedDelay = 1800000, initialDelay = 1000)
    public void everyHalfHour() {
        scheduleServiceList.forEach(ScheduleService::everyHalfHour);
    }

}
